package com.gmm.springboot.admin.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan(basePackages = { "com.gmm.springboot.admin.mapper.test02" }, sqlSessionFactoryRef = "sqlSessionFactoryDbTest02")
public class DbTest02Config {

	@Autowired
	@Qualifier("dataSourceDbTest02")
	private DataSource dataSourceDbTest02;

	@Bean
	public SqlSessionFactory sqlSessionFactoryDbTest02() throws Exception {
		SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
		factoryBean.setDataSource(dataSourceDbTest02);

		return factoryBean.getObject();
	}

	@Bean
	public SqlSessionTemplate sqlSessionTemplateDbTest02() throws Exception {
		SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactoryDbTest02()); // 使用上面配置的Factory
		return template;
	}
}
